t = int(input())
# 1 3 4
# -1 2 3 4
for _ in range(t):
    n, m, k = map(int, input().split())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    a.sort()
    b.sort()
    res = 0
    j = 0
    for i in range(n):
        while j < m and b[j] < a[i] and a[i] - b[j] > k:
            j+=1;
        if j >= m:
            break
        if abs(a[i] - b[j]) < k:
            res+=1
        j+=1
    print(res)